<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools 1.3 Documentation - Utilities/Cookie</title>
</head>

<body>
  <div id="docs" class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Cookie">Cookie</a></h4>
      <div class="menu-item"><a href="#Cookie:write">write</a></div>
      <div class="menu-item"><a href="#Cookie:read">read</a></div>
      <div class="menu-item"><a href="#Cookie:dispose">dispose</a></div>
    </div>
    <div class="l-border r-border span-15 content">
      <h1 id="Cookie"><a href="#Cookie">Object: Cookie</a></h1>
      <p class="description">Sets and accesses cookies.</p>
      <h3>Credits:</h3>
      <ul>
        <li>Based on the functions by Peter-Paul Koch <a href="http://www.quirksmode.org">QuirksMode</a>.</li>
      </ul>
      <h3 id="Cookie-options">Options:</h3>
      <ul>
        <li>domain   - (<em>string</em>: defaults to false) The domain the Cookie belongs to.</li>
        <li>path     - (<em>string</em>: defaults to '/') The path the Cookie belongs to.</li>
        <li>duration - (<em>number</em>: defaults to false) The duration of the Cookie before it expires, in days. If set to false or 0, the cookie will be a session cookie that expires when the browser is closed.</li>
        <li>secure   - (<em>boolean</em>: defaults to false) Stored cookie information can be accessed only from a secure environment.</li>
      </ul>
      <h3>Notes:</h3>
      <ul>
        <li>In order to share the Cookie with pages located in a different path, the <a href="#Cookie-options">Cookie.options.domain</a> value must be set.</li>
      </ul>
      <h2 id="Cookie:write"><a href="#Cookie:write">Cookie Method: write</a></h2>
      <p class="description">Writes a cookie in the browser.</p>
      <h3>Syntax:</h3>
      <pre class="javascript"><span class="kw2">var</span> myCookie = Cookie.<span class="kw1">write</span><span class="br0">(</span>key, value<span class="br0">[</span>, options<span class="br0">]</span><span class="br0">)</span>;

</pre>
      <h3>Arguments:</h3>
      <ol>
        <li>key     - (<em>string</em>) The key (or name) of the cookie.</li>
        <li>value   - (<em>string</em>) The value to set. Cannot contain semicolons.</li>
        <li>options - (<em>mixed</em>, optional) See <a href="#Cookie">Cookie</a>.</li>
      </ol>
      <h3>Returns:</h3>
      <ul>
        <li>(<em>object</em>) An object with the options, the key and the value. You can give it as first parameter to Cookie.remove.</li>
      </ul>
      <h3>Examples:</h3>
      <p>Saves the Cookie for the Duration of the Session:</p>
      <pre class="javascript"><span class="kw2">var</span> myCookie = Cookie.<span class="kw1">write</span><span class="br0">(</span><span class="st0">'username'</span>, <span class="st0">'Harald'</span><span class="br0">)</span>;

</pre>
      <p>Saves the Cookie for a Day:</p>
      <pre class="javascript"><span class="kw2">var</span> myCookie  = Cookie.<span class="kw1">write</span><span class="br0">(</span><span class="st0">'username'</span>, <span class="st0">'JackBauer'</span>, <span class="br0">{</span>duration: <span class="nu0">1</span><span class="br0">}</span><span class="br0">)</span>;

</pre>
      <h2 id="Cookie:read"><a href="#Cookie:read">Cookie Method: read</a></h2>
      <p class="description">Reads the value of a Cookie.</p>
      <h3>Syntax:</h3>
      <pre class="javascript"><span class="kw2">var</span> myCookie = Cookie.<span class="me1">read</span><span class="br0">(</span><span class="kw3">name</span><span class="br0">)</span>;

</pre>
      <h3>Arguments:</h3>
      <ol>
        <li>name - (<em>string</em>) The name of the Cookie to retrieve.</li>
      </ol>
      <h3>Returns:</h3>
      <ul>
        <li>(<em>mixed</em>) The cookie string value, or null if not found.</li>
      </ul>
      <h3>Examples:</h3>
      <pre class="javascript">Cookie.<span class="me1">read</span><span class="br0">(</span><span class="st0">'username'</span><span class="br0">)</span>;
</pre>
      <h2 id="Cookie:dispose"><a href="#Cookie:dispose">Cookie Method: dispose</a></h2>
      <p class="description">Removes a cookie from the browser.</p>
      <h3>Syntax:</h3>
      <pre class="javascript"><span class="kw2">var</span> oldCookie = Cookie.<span class="me1">dispose</span><span class="br0">(</span>cookie<span class="br0">[</span>, options<span class="br0">]</span><span class="br0">)</span>;
</pre>
      <h3>Arguments:</h3>
      <ol>
        <li>name  - (<em>string</em>) The name of the cookie to remove or a previously saved Cookie instance.</li>
        <li>options - (<em>object</em>, optional) See <a href="#Cookie">Cookie</a>.</li>
      </ol>
      <h3>Examples:</h3>
      <p>Remove a Cookie:</p>
      <pre class="javascript">Cookie.<span class="me1">dispose</span><span class="br0">(</span><span class="st0">'username'</span><span class="br0">)</span>; <span class="co1">//Bye-bye JackBauer! Seeya in 24 Hours.</span>
</pre>
      <p>Creating a Cookie and Removing it Right Away:</p>
      <pre class="javascript"><span class="kw2">var</span> myCookie = Cookie.<span class="kw1">write</span><span class="br0">(</span><span class="st0">'username'</span>, <span class="st0">'Aaron'</span>, <span class="br0">{</span>domain: <span class="st0">'mootools.net'</span><span class="br0">}</span><span class="br0">)</span>;
<span class="kw1">if</span> <span class="br0">(</span>Cookie.<span class="me1">read</span><span class="br0">(</span><span class="st0">'username'</span><span class="br0">)</span> == <span class="st0">'Aaron'</span><span class="br0">)</span> <span class="br0">{</span> myCookie.<span class="me1">dispose</span><span class="br0">(</span><span class="br0">)</span>; <span class="br0">}</span>

</pre>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>